package org.evej.apiparser.model.character;

import org.evej.apiparser.model.ApiDocumentModel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ApiAssetContainer<T extends Asset> extends ApiAsset implements Assets, ApiDocumentModel {

    private static final long serialVersionUID = 8767362392L;
    private final List<T> childAssets;

    protected ApiAssetContainer(List<T> assets, long itemID, long itemType, long quantity, long locationID, int flag) {
        super(itemID, itemType, quantity, locationID, flag);
        childAssets = assets;
    }

    @Override
    public List<T> getAssets() {
        return childAssets;
    }

    public static class Builder<T extends Asset> implements Assets, Serializable {
        private List<T> childAssets = new ArrayList<>();
        private Builder parent;

        private long itemID;
        private long quantity;
        private long itemType;
        private long locationID;
        private int flag;

        public Builder() { }

        public Builder(Builder parent, long itemID, long itemType, long quantity, long locationID, int flag) {
            this.itemID = itemID;
            this.itemType = itemType;
            this.quantity = quantity;
            this.locationID = locationID;
            this.flag = flag;
            this.parent = parent;
        }

        @Override
        public long getItemID() {
            return 0;
        }

        @Override
        public long getItemType() {
            return 0;
        }

        @Override
        public long getQuantity() {
            return 0;
        }

        @Override
        public long getLocationID() {
            return 0;
        }

        @Override
        public int getFlag() {
            return 0;
        }

        @Override
        public List<T> getAssets() {
            return childAssets;
        }

        public Builder getParent() {
            return parent;
        }

        public void addAsset(T asset) {
            childAssets.add(asset);
        }

        public ApiAssetContainer build() {
            return new ApiAssetContainer(Collections.unmodifiableList(childAssets), itemID, itemType,
                    quantity, locationID, flag);
        }
    }
}
